package cn.zswltech.gruul.web.api.intercept;

import cn.hutool.core.util.StrUtil;
import cn.zswltech.gruul.auth.ApplicationAuthChecker;
import cn.zswltech.gruul.auth.AuthCheckerDispatcher;
import cn.zswltech.gruul.biz.service.GroupOaService;
import cn.zswltech.gruul.biz.service.LoginService;
import cn.zswltech.gruul.common.constant.SystemConstant;
import cn.zswltech.gruul.common.result.MSG;
import cn.zswltech.gruul.common.result.Response;
import cn.zswltech.gruul.common.entity.UserDO;
import cn.zswltech.gruul.domain.entity.CheckResult;
import cn.zswltech.gruul.web.api.util.*;
import com.alibaba.fastjson.JSON;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.HandlerMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import static cn.zswltech.gruul.web.api.util.RequestUtil.getIpAddr;


public class SystemInterceptor implements HandlerInterceptor {

    @Autowired
    private AuthCheckerDispatcher authCheckerDispatcher;

    /**
     * auth相关接口不需要走此拦截器
     *
     * @param request
     * @param response
     * @param handler
     * @return boolean
     * @author xuluquan
     * @date 2020-04-05 15:32
     */
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
        ApplicationAuthChecker applicationAuthChecker = authCheckerDispatcher.routeAuthChecker();
        return applicationAuthChecker.check(request,response,handler);
    }



    @Override
    public void postHandle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, ModelAndView modelAndView) throws Exception {

    }

    @Override
    public void afterCompletion(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, Exception e) throws Exception {
        WhiteListUtil.reset();
    }






}
